/**
 * 
 */

/**
 * @author IBRAHIMLI NIhat
 * @author BAYRAMOV Matin
 * 
 */
public class Edge implements Comparable<Edge> {

	private Task from;

	private Task to;

	private int weight;

	public Edge(Task from, Task to, int weight) {
		this.setFrom(from);
		this.setTo(to);
		this.setWeight(weight);
	}

	/**
	 * @return the from
	 */
	public Task getFrom() {
		return from;
	}

	/**
	 * Get a random weight for an endge
	 * 
	 * @param maxNumber
	 * @return
	 */
	public static int getRandomWeight(int maxNumber) {
		int weight = 1 + (int) (Math.random() * (maxNumber - 1));
		return weight;
	}

	/**
	 * @param from
	 *            the from to set
	 */
	public void setFrom(Task from) {
		if (from != null) {
			this.from = from;
		}
	}

	/**
	 * @return the to
	 */
	public Task getTo() {
		return to;
	}

	/**
	 * @param to
	 *            the to to set
	 */
	public void setTo(Task to) {
		this.to = to;
	}

	/**
	 * @return the weight
	 */
	public int getWeight() {
		return weight;
	}

	/**
	 * @param weight
	 *            the weight to set
	 */
	public void setWeight(int weight) {
		this.weight = weight;
	}

	public String toString() {
		String str = "";
		// String str = "[ ";
		// str += "t" + this.from.getId() + ", ";
		// str += "t" + this.to.getId() + ", ";
		str += this.weight;

		return str;
	}

	@Override
	public int compareTo(Edge o) {
		if (this.from.compareTo(o.from) == 0) {
			if (this.to.compareTo(o.to) == 0) {
				return 0;
			}
		}

		return 1;
	}

}
